<div class="host-torrents-wrapper">
  <div class="host">
	<%= form_for(@host) do |f| %>
	  <% if @host.errors.any? %>
		<div id="error_explanation">
		  <h2><%= pluralize(@host.errors.count, "error") %> prohibited this host from being saved:</h2>

		  <ul>
		  <% @host.errors.full_messages.each do |msg| %>
			<li><%= msg %></li>
		  <% end %>
		  </ul>
		</div>
	  <% end %>

    <% if @host.persisted? %>
      <h3> Manager Settings </h3>
    <% end %>
	  <div class="field">
		<%= f.label :name %><br />
		<%= f.text_field :name %>
	  </div>
	  <div class="field">
		<%= f.label :ip %><br />
		<%= f.text_field :ip %>
	  </div>
	  <div class="field">
		<%= f.label :description %><br />
		<%= f.text_area :description, :rows => 3%>
	  </div>
	  <div class="actions">
		<%= f.submit (@host.persisted? ? "Update host details" : "Save") %>
	  </div>
	<% end %>

    <% if @host.persisted? %>
      <h3> Configurations </h3>

      <% {
        max_upload: "Max Uploads:",
        max_download: "Max Uploads:",
        max_active: "Max Active:",
        a: "peers changed allowed?",
        b: "uTorrent port:"
      }.each do |k,v| %>

        <form action="<%= set_attribute_host_url(@host)%>" method="POST">
          <input type="hidden" name="attribute" value="<%=k%>">
          <%=v%> <input name="value" type="text" size=4 value="<%=@host.send("get_#{k}")%>"> <%= submit_tag "Set" %>
        </form>
      <% end %>
    <% end %>
  </div>

  <% if @host.persisted? %>
    <div class="torrents">
      <h3>Index </h3>
      <h4> Torrents </h4>
      <ul>
        <% @host.torrents.each do |torrent| %>
          <li><%= link_to torrent[:name], "##{torrent[:name]}" %></li>
        <% end %>
      </ul>
      <h4> Custom </h4>
      <%= link_to "Custom OIDs", "#custom_oids"%>
    </div>
  <% end %>
</div>


<% if @host.persisted? %>
<h2> Host torrents </h2>
<div class="host_torrents">
  <% if @host.torrents_active? %>
    <span class="oid_active">Running. <%= link_to "Deactivate", torrents_deactivate_host_path(@host), :method => :post %></span>
  <% else %>
    <span class="oid_not_active">Stopped. <%= link_to "Activate", torrents_activate_host_path(@host), :method => :post %></span>
  <% end %>
<%= render :partial => "torrents_table", :locals => {:host => @host} %>
</div>
<% end %>



<h2><a name="custom_oids">Host custom oids</a></h2>
<%= link_to 'New Oid', new_oid_path + "?host_id=#{@host.id}" %>

<% @host.oids.each do |oid| %>
	<div class="host_oid">
		<% @oid = oid %>
    <h1> <%= @oid.name %> </h1>
		<%= render :partial => "oids/form" %>
	</div>
<% end %>
